class Solution
{
public:
    int kthFactor(int n, int k)
    {
        int factorId = 0;
        for (int i = 1; i <= n; ++i)
        {
            if (n % i == 0)
            {
                ++factorId;
                if (factorId == k)
                {
                    return i;
                }
            }
        }
        return -1;
    }
};